package task

import (
	"fmt"
	"singo/cache"
	"singo/model"
)

// UserListSaveRedisHash 将用户信息存入Redis Hash
func UserListSaveRedisHash() {
	users := []model.User{}
	if err := model.DB.Find(&users).Error; err != nil {
		fmt.Println("User List Save Into RedisHash Mysql Error", err)
	}
	for _, item := range users {
		user := map[string]interface{}{
			"nickname":   item.Nickname,
			"username":   item.UserName,
			"user_type":  item.UserType,
			"orgization": item.OrganizationUID,
		}
		// fmt.Println("添加 Redis 用户记录", item.UID, item.Nickname)
		//添加 Redis 用户记录
		if err := cache.RedisClient.HMSet(item.UID, user).Err(); err != nil {
			fmt.Println("User List Save Into RedisHash Redis Error", err)
		}
	}
	// user, err := cache.RedisClient.HMGet("75416221-71c7-4bcd-94a6-b13c3c44eda8", "nickname", "username").Result()
	// if err != nil {
	// 	fmt.Println("User List Get RedisHash Redis Error", err)
	// }
	// fmt.Println(user)
}
